<?php
	$studentview = "student";
	class Student extends Controller{
		
		function Student(){
			parent::Controller();
		}

		function index(){	
			$data['id'] = $this->session->userdata('id');
			$gate['body'] = $this->load->view('student/student_home', $data, TRUE);
			$this->load->view('student', $gate);
		}
		
		function edit_profile(){
			$data = array();
			$data['id'] = $this->session->userdata('userid');	
			$reguser = $this->Register->selectStudent($data['id']);

			$rules['lastname'] = "required";
			$rules['firstname'] = "required";
			$rules['middlename'] = "required";
			$rules['address'] = "required";
			$rules['occupation'] = "required";

			$this->validation->set_rules($rules);
			$this->validation->set_error_delimiters('<div id="error">', '</div>');

			if ($this->validation->run()==TRUE){
				$reguser["lastname"] = $this->input->post("lastname");
				$reguser["firstname"] = $this->input->post("firstname");
				$reguser["middlename"] = $this->input->post("middlename");
				$reguser["sex"] = $this->input->post("sex");
				$reguser["address"] = $this->input->post("address");
				$reguser["occupation"] = $this->input->post("occupation");
				$this->Register->update($reguser, $this->session->userdata('userid'));
			}

			$data['reguser'] = $reguser;
			$gate["body"] = $this->load->view("student/edit_profile", $data, TRUE);
			$this->load->view('student', $gate);
		}
		
		function enlist(){
			global $studentview;
			$data = array();
			$student = array();
			$student["body"] = $this->load->view("student/search", $data, TRUE);
			$this->load->view($studentview, $student);
		}
		
		function results(){
			global $studentview;
			$data = array();
			$student = array();
			$student["body"] = $this->load->view("student/results", $data, TRUE);
			$this->load->view($studentview, $student);
		}
		
		function viewTeacher($teacherid, $subjectid){
			global $studentview;
			$data = array(
			              "teacherid" => $teacherid,
			              "subjectid" => $subjectid,
			             );
			$student = array();
			$student["body"] = $this->load->view("student/viewTeacher", $data, TRUE);
			$this->load->view($studentview, $student);
		}
		
		function reserve($teacherid, $date, $time, $studentid){
			global $studentview;
			$time = str_replace("-", ":", $time);
			$constraints = array(
			                     "teacherid" => $teacherid,
			                     "date" => $date,
			                     "time" => $time
			                    );
			$this->db->where("teacherid", $teacherid);
			$this->db->where("time", $time);
			$this->db->where("date", $date);
			$this->db->update("schedule", array("studentid" => $studentid));
			$student["body"] = $this->load->view("student/reserved", $constraints, TRUE);
			$this->load->view($studentview, $student);
			
		}
	}
?>
